﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.People
{
    public partial class PeopleInputFields : SERP.Modules.ModuleBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadLanguage();
        }
        private PeopleEntity model = new PeopleEntity();
        public PeopleEntity Model
        {
            set
            {
                model = value;
            }
            get
            {
                return model;
            }
        }
        //Load All lable text
        private void LoadLanguage()
        {
            labelPersonCode.Text = PeopleStringMapping.PersonCode + ":";
            labelFullName.Text = PeopleStringMapping.FullName + ":";
            labelGender.Text = PeopleStringMapping.Gender + ":";
            validRQGender.ErrorMessage = Constants.APP_REQUIRE_WARNING;
            labelBirthDay.Text = PeopleStringMapping.BirthDay + ":";
            labelAddress.Text = PeopleStringMapping.Address + ":";
            labelPhone.Text = PeopleStringMapping.Phone + ":";
            labelEmail.Text = PeopleStringMapping.Email + ":";
            labelPositionId.Text = PeopleStringMapping.PositionId + ":";
            validRQPositionId.ErrorMessage = Constants.APP_REQUIRE_WARNING;
            validExpressionPositionId.ErrorMessage = Constants.APP_REQUIRE_INTERGER_WARNING;
            labelStartDate.Text = PeopleStringMapping.StartDate + ":";
            labelNote.Text = PeopleStringMapping.Note + ":";
            labelUserId.Text = PeopleStringMapping.UserId + ":";
            validRQUserId.ErrorMessage = Constants.APP_REQUIRE_WARNING;
            validExpressionUserId.ErrorMessage = Constants.APP_REQUIRE_INTERGER_WARNING;
            labelOrganizationId.Text = PeopleStringMapping.OrganizationId + ":";
            validRQOrganizationId.ErrorMessage = Constants.APP_REQUIRE_WARNING;
            labelPersonTypeId.Text = PeopleStringMapping.PersonTypeId + ":";
            validRQPersonTypeId.ErrorMessage = Constants.APP_REQUIRE_WARNING;
        }
        public void UpdateToModel()
        {
            model.PersonCode = Convert.ToString(txtPersonCode.Text);
            model.FullName = Convert.ToString(txtFullName.Text);
            model.Gender = Convert.ToByte(txtGender.SelectedValue);
            model.BirthDay = txtBirthDay.SelectedDate.Value;
            model.Address = Convert.ToString(txtAddress.Text);
            model.Phone = Convert.ToString(txtPhone.Text);
            model.Email = Convert.ToString(txtEmail.Text);
            model.PositionId = Convert.ToInt32(txtPositionId.Text);
            model.StartDate = txtStartDate.SelectedDate.Value;
            model.Note = Convert.ToString(txtNote.Text);
            model.UserId = Convert.ToInt32(txtUserId.Text);
            model.OrganizationId = Convert.ToInt32(txtOrganizationId.SelectedValue);
            model.PersonTypeId = Convert.ToInt32(txtPersonTypeId.SelectedValue);
        }
        public void UpdateToScreen()
        {
            txtPersonCode.Text = model.PersonCode;
            txtFullName.Text = model.FullName;
            txtGender.SelectedValue = Convert.ToString(model.Gender);
            txtBirthDay.SelectedDate = model.BirthDay;
            txtAddress.Text = model.Address;
            txtPhone.Text = model.Phone;
            txtEmail.Text = model.Email;
            txtPositionId.Text = Convert.ToString(model.PositionId);
            txtStartDate.SelectedDate = model.StartDate;
            txtNote.Text = model.Note;
            txtUserId.Text = Convert.ToString(model.UserId);
            txtOrganizationId.SelectedValue = model.OrganizationId.ToString();
            txtPersonTypeId.SelectedValue = model.PersonTypeId.ToString();
        }
        public void ClearScreen()
        {
            txtPersonCode.Text = "";
            txtFullName.Text = "";
            txtAddress.Text = "";
            txtPhone.Text = "";
            txtEmail.Text = "";
            txtPositionId.Text = "0";
            txtNote.Text = "";
            txtUserId.Text = "0";
        }
        public bool ValidateScreen()
        {
            bool result = true;
            if (txtOrganizationId.SelectedIndex <= 0)
            {
                result = false;
                validRQOrganizationId.IsValid = false;
            }
            else
            {
                validRQOrganizationId.IsValid = true;
            }
            if (txtPersonTypeId.SelectedIndex <= 0)
            {
                result = false;
                validRQPersonTypeId.IsValid = false;
            }
            else
            {
                validRQPersonTypeId.IsValid = true;
            }
            if (txtGender.SelectedIndex <= 0)
            {
                result = false;
                validRQGender.IsValid = false;
            }
            else
            {
                validRQGender.IsValid = true;
            }
            return result;
        }
    }
}
